package com.fafa.File;

import java.io.*;

public class FileCopyImage {
    public static void main(String[] args) {
        //创建输入流，读入到程序
        File readfile = new File("E:\\image\\1.png");
        File writefile = new File("E:\\2.png");
        FileOutputStream fileOutputStream = null;
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(readfile);
            fileOutputStream = new FileOutputStream(writefile);

            byte[] buf = new byte[1024];
            int len = 0;
            //将读到的写入，边读边写
            while ((len = fileInputStream.read(buf)) != -1) {
                //读了几个写几个
                fileOutputStream.write(buf, 0, len);
            }
            System.out.println("拷行完毕");

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                fileOutputStream.close();
                fileInputStream.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

        }
        //创建输出流，写入到指定的位置
    }



}


